#include "miniRobotAbout.h"

#include <QHBoxLayout>
#include <QIcon>
#include <QVBoxLayout>
#include <QGridLayout>

#include "ElaImageCard.h"
#include "ElaText.h"
// #include "ConfigManager.h"

// using namespace framework;

miniRobotAbout::miniRobotAbout(QWidget* parent) : ElaDialog(parent)
{
    // QString machineType = QString::fromStdString(ConfigManager::getInstance().machineNameStr + "机型");
    QString machineType = "800机型";
    bool handel380Enable = true;    // 380控制盒使能状态
    bool xboxGamepadEnable = true;  // xbox使能状态

    QString title = "关于: VVLAI机器人上位机软件";
    setWindowTitle(title);
    setWindowIcon(QIcon(":/include/Image/Moon.jpg"));
    this->setIsFixedSize(true);                            // 设置窗口固定大小
    setWindowModality(Qt::ApplicationModal);               // 当此对话框打开时，会阻塞整个应用程序的其他窗口操作
    setWindowButtonFlags(ElaAppBarType::CloseButtonHint);  // 只有关闭功能

    // 左侧图标
    ElaImageCard* pixCard = new ElaImageCard(this);
    pixCard->setFixedSize(60, 60);
    pixCard->setIsPreserveAspectCrop(false);
    pixCard->setCardImage(QImage(":/include/Image/Moon.jpg"));

    QVBoxLayout* pixCardLayout = new QVBoxLayout();
    pixCardLayout->addWidget(pixCard);
    pixCardLayout->addStretch();

    // 软件名称和版本
    QString softName = "VVLAI机器人上位机软件 - " + machineType;
    ElaText* softwareName = new ElaText(softName, this);
    QFont nameFont = softwareName->font();
    nameFont.setWeight(QFont::Bold);
    softwareName->setFont(nameFont);
    softwareName->setWordWrap(false);
    softwareName->setTextPixelSize(16);

    // 主要功能 - 使用网格布局实现一行两个
    ElaText* functionText = new ElaText("主要功能", this);
    functionText->setWordWrap(false);
    functionText->setTextPixelSize(14);
    functionText->setFont(QFont("", -1, QFont::Bold));

    QGridLayout* functionGridLayout = new QGridLayout();
    functionGridLayout->setHorizontalSpacing(20);
    functionGridLayout->setVerticalSpacing(5);

    // 第一行
    ElaText* func1 = new ElaText("• 水下机器人运动控制", this);
    func1->setWordWrap(true);
    func1->setTextPixelSize(12);
    functionGridLayout->addWidget(func1, 0, 0);

    ElaText* func2 = new ElaText("• 机器人状态实时监测", this);
    func2->setWordWrap(true);
    func2->setTextPixelSize(12);
    functionGridLayout->addWidget(func2, 0, 1);

    // 第二行
    ElaText* func3 = new ElaText("• 机械臂精准控制", this);
    func3->setWordWrap(true);
    func3->setTextPixelSize(12);
    functionGridLayout->addWidget(func3, 1, 0);

    ElaText* func4 = new ElaText("• 水下摄像监控系统", this);
    func4->setWordWrap(true);
    func4->setTextPixelSize(12);
    functionGridLayout->addWidget(func4, 1, 1);

    // 第三行
    ElaText* func5 = new ElaText("• 截屏与录像功能", this);
    func5->setWordWrap(true);
    func5->setTextPixelSize(12);
    functionGridLayout->addWidget(func5, 2, 0);

    ElaText* func6 = new ElaText("• 连接状态监测", this);
    func6->setWordWrap(true);
    func6->setTextPixelSize(12);
    functionGridLayout->addWidget(func6, 2, 1);

    // 控制设备 - 单独一项
    ElaText* controlText = new ElaText("控制设备", this);
    controlText->setWordWrap(false);
    controlText->setTextPixelSize(14);
    controlText->setFont(QFont("", -1, QFont::Bold));

    // 根据控制手柄状态显示对应的控制设备
    QString controlDeviceText;
    if (handel380Enable && xboxGamepadEnable)
    {
        controlDeviceText = "• 380控制盒 + Xbox游戏手柄";
    }
    else if (handel380Enable)
    {
        controlDeviceText = "• 380控制盒";
    }
    else if (xboxGamepadEnable)
    {
        controlDeviceText = "• Xbox游戏手柄";
    }
    else
    {
        controlDeviceText = "• 多种控制设备";
    }

    ElaText* controlDetail = new ElaText(controlDeviceText, this);
    controlDetail->setWordWrap(true);
    controlDetail->setTextPixelSize(12);

    // 技术参数
    ElaText* paramText = new ElaText("技术参数", this);
    paramText->setWordWrap(false);
    paramText->setTextPixelSize(14);
    paramText->setFont(QFont("", -1, QFont::Bold));

    ElaText* paramDetail = new ElaText("• 最大工作深度: 200米\n• 支持多路摄像头输入", this);
    paramDetail->setWordWrap(true);
    paramDetail->setTextPixelSize(12);

    // 公司信息
    ElaText* companyText = new ElaText("山东未来机器人有限公司", this);
    companyText->setWordWrap(false);
    companyText->setTextPixelSize(14);
    companyText->setFont(QFont("", -1, QFont::Bold));


    // 网址布局
    ElaText* websiteText = new ElaText("网址: www.vvlai.com / www.vvlai.cn", this);
    websiteText->setWordWrap(false);
    websiteText->setTextPixelSize(12);

    // 电话信息
    ElaText* contactText = new ElaText("电话: 0631-5326187", this);
    contactText->setWordWrap(false);
    contactText->setTextPixelSize(12);

    // 版权信息
    ElaText* copyrightText = new ElaText("版权所有 © 2025 山东未来机器人有限公司", this);
    copyrightText->setWordWrap(false);
    copyrightText->setTextPixelSize(12);
    copyrightText->setStyleSheet("color: gray;");

    // 文本布局
    QVBoxLayout* textLayout = new QVBoxLayout();
    textLayout->setSpacing(10);
    textLayout->addWidget(softwareName);
    textLayout->addSpacing(15);

    textLayout->addWidget(functionText);
    textLayout->addSpacing(5);
    textLayout->addLayout(functionGridLayout);
    textLayout->addSpacing(10);

    textLayout->addWidget(controlText);
    textLayout->addSpacing(5);
    textLayout->addWidget(controlDetail);
    textLayout->addSpacing(10);

    textLayout->addWidget(paramText);
    textLayout->addSpacing(5);
    textLayout->addWidget(paramDetail);
    textLayout->addSpacing(15);

    // 添加弹簧将公司信息推到底部
    textLayout->addStretch();

    textLayout->addWidget(companyText);
    textLayout->addSpacing(5);
    textLayout->addWidget(websiteText);
    textLayout->addWidget(contactText);
    textLayout->addSpacing(10);
    textLayout->addWidget(copyrightText);

    // 内容布局
    QHBoxLayout* contentLayout = new QHBoxLayout();
    contentLayout->addSpacing(20);
    contentLayout->addLayout(pixCardLayout);
    contentLayout->addSpacing(20);
    contentLayout->addLayout(textLayout);
    contentLayout->addSpacing(10);

    // 主布局
    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->setContentsMargins(0, 25, 0, 20);
    mainLayout->addLayout(contentLayout);
}

miniRobotAbout::~miniRobotAbout()
{
}